// pages/authentication/authentication.js
var GlobalData = require('../../utils/GlobalData.js');
var dataManager = require('../../utils/dataManager.js');
var app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    name: "",
    idCard: ""

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  inputName(e) {
    var code = e.detail.value.trim();
    this.setData({
      name: e.detail.value.trim()
    })
  },
  inputIDcard(e) {
    var code = e.detail.value.trim();
    this.setData({
      idCard: e.detail.value.trim()
    })
  },
  //认证
  onAuthentication() {
    console.log(this.data.name)
    console.log(this.data.idCard)
    if (this.data.name == "" || this.data.idCard == "") {
      app.onshowModal("请输入正确信息");
      return;
    }
    if (this.data.idCard.length != 18) {
      app.onshowModal("请输入18位数的身份证号码");
      return;
    }
    console.log("通过")
    // try {
    //   dataManager.OnRequestPost()
    //   dataManager.OnRequestPost({ method: "modifytruename", "token": GlobalData.token, truename: this.data.name, idcard: this.data.idCard }, this.oonAuthenticationComplete);
    // } catch (err) {
    //   console.log(err)
    // }
  },
  oonAuthenticationComplete(data) {
    console.log(GlobalData.HomeData);

    dataManager.rigisterObserver("home", this.onGetHomeDataComplete, this)
    dataManager.getHomeData();
    //请求homeData数据
  },
  onGetHomeDataComplete(data) {
    var that = this
    GlobalData.homeData = data;
    // this.app.show("提示", "已完成认证", "确认", "withdraw/home");
    wx.showModal({
      title: '提示',
      content: "已完成认证",
      showCancel: false,
      success: function (res) {
        if (that.data.sourceUrl)
          wx.navigateBack({
            delta: 1
          })
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})